function EventEmitter() {
  this._events = {};
}
EventEmitter.prototype.on = function (eventName, fn) {
  if (!this._events) this._events = {};
  (this._events[eventName] || (this._events[eventName] = [])).push(fn);
};
EventEmitter.prototype.once = function (eventName, fn) {
  const one = (...args) => {
    // 绑定后移除
    fn.call(this,...args)
    this.off(eventName, one); // 执行后移除掉one
  };
  one.l = fn
  this.on(eventName, one); // 这里绑定的是one  但是外面可能要移除fn
};
EventEmitter.prototype.emit = function (eventName, ...args) {
  if (!this._events) this._events = {};
  let events = this._events[eventName];
  if (events) {
    events.forEach((fn) => fn(...args));
  }
};
EventEmitter.prototype.off = function (eventName, fn) {
  if (!this._events) this._events = {};
  let events = this._events[eventName];
  if (events) {
    this._events[eventName] = events.filter((item) => (item !== fn && item.l !== fn));
  }
};
module.exports = EventEmitter;
